/**
 * 轻型Js类库
 */

var cjl = new Base();

function Base(){
	this.post = function(url,params,callback){
		alert("post is called");
		$.post(url,params, function(json){
			var obj;
			if(typeof(json) == 'string') {
				obj = JSON.parse(json);
			} else {
				obj = json;
			}
			
			if(obj.code == 401){
				document.location = "/mobile/login.html";	
			}else if(obj.code == 0){
				callback(obj.body);
			}else{
				alert(obj.msg);
			}
		});
	};

	this.get = function(url, params, callback){
		alert("get is called");
		$.get(url, params, function(json){
			var obj;
			if(typeof(json) == 'string') {
				obj = JSON.parse(json);
			} else {
				obj = json;
			}
			if(obj.code == 401){
				document.location = "/mobile/login.html";	
			} else if(obj.code == 0) {
				callback(obj.body);
			} else {
				alert(obj.msg);
			}
		});
	};
	
	this.requestData = function(name){
		alert("requestData is called");
		var strHref = window.location.href;
		var pos = strHref.indexOf("?");
		var strRight = strHref.substr(pos + 1);
		var arrayTmp = strRight.split("&");
		for(var i=0;i<arrayTmp.length;i++){
			var tmp = arrayTmp[i].split("=");
			if(tmp[0]==name){
				return tmp[1];
			}
		}
	};
	
	this.formatTime = function(date, pattern) {
		//return new Date(date).format("yyyy-MM-dd HH:mm:ss");
		return new Date(date).format(pattern);
	};
	
	this.initTitle = function() {
		alert("initTitle is called");
		return;
	};

};

Date.prototype.format =function(format)
{
	var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(), //day
		"H+" : this.getHours(), //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter
		"S" : this.getMilliseconds() //millisecond
	};
	
	if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
	(this.getFullYear()+"").substr(4- RegExp.$1.length));
	for(var k in o)if(new RegExp("("+ k +")").test(format))
	format = format.replace(RegExp.$1,
	RegExp.$1.length==1? o[k] :
	("00"+ o[k]).substr((""+ o[k]).length));
	return format;
};